package com.example.pmanagesys.mapper;

import com.example.pmanagesys.entity.Attendance;
import com.example.pmanagesys.entity.applyFor;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AttendanceMapper {

    // 查询某一页的数据 ，分页
    List<Attendance> selectPage(@Param("pageNum") Integer pageNum,
               @Param("pageSize") Integer pageSize,
               @Param("z_name") String z_name,
               @Param("startDate") String startDate,
               @Param("endDate") String endDate);
    // 查询总条数
    Integer selectTotal(@Param("z_name") String z_name,
                        @Param("startDate") String startDate,
                        @Param("endDate") String endDate);

    // admin 修改
    int update(Attendance attendance);

    // admin 批量修改
    Integer updateBatchByIds( @Param("notes") String notes,@Param("ids") List<Integer> ids);

    // user 提交申请 新增
    @Insert("insert into sys_applyfor( attend_id,z_name, department, leaderName, notes, bu_time, state)" +
            "VALUES (#{attend_id},#{z_name},#{department},#{leaderName},#{notes},#{bu_time}, #{state})")
    int add(applyFor applyFor);
    // 提交申请之后修改
    @Update("UPDATE sys_attend set bu_state='审批中' WHERE id = #{id}")
    int userupdate(applyFor applyFor);

    // 待办 查询
    @Select("select *  from sys_applyfor where leaderName = #{leaderName}  and state ='true'")
    List<applyFor> allFind(@Param("leaderName") String leaderName);
    // 待办总条数  查询
    @Select("select count(*)  from sys_applyfor where leaderName = #{leaderName} and state ='true' ")
    Integer selectcount(@Param("leaderName") String leaderName);

    // 待办 同意/拒绝 修改
    @Update("UPDATE sys_applyfor SET state='false',userState='true', overtime=#{overtime} , result=#{result} WHERE id= #{id};")
    Integer agreeUpdate(@Param("result") String result,@Param("overtime") String overtime,@Param("id")  int id);

    // 待办 拒绝 修改
    @Update("UPDATE sys_attend set bu_state='拒绝' WHERE id = #{id}")
    int refuseUpdate(@Param("id") int id);

    // 消息  获取对应 消息通知
    @Select("select *  from sys_applyfor where z_name = #{z_name}  and state ='false'  order by id desc")
    List<applyFor> messageFind(@Param("z_name") String z_name);
    // 消息 条数
    @Select("select count(*)  from sys_applyfor where z_name = #{z_name}  and state ='false' and userState='true'")
    Integer messageCount(@Param("z_name") String z_name);

    // 消息 已读 修改
    @Update("UPDATE sys_applyfor set userState='false' WHERE id = #{id}")
    Integer readUpdate(@Param("id") int id);

}
